package com.zerdoor.service.impl;

import com.zerdoor.dao.BidDao;
import com.zerdoor.dao.TaskDetailDao;
import com.zerdoor.service.BidService;
import com.zerdoor.service.TaskDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by xiaoji on 2014/11/6.
 */
@Service
public class BidServiceImpl implements BidService {
    @Autowired
    private BidDao bidDao;
    @Autowired
    private TaskDetailService taskDetailService;

    @Override
    public Map<String, Object> getTaskInfoByTaskId(Integer taskId) {
        return bidDao.getTaskInfoByTaskId(taskId);
    }

    @Override
    public Map<String, Object> addBidInfo(Map<String, Object> map) {
        Map<String, Object> result = new HashMap<String, Object>();
        //验证任务是否在竞标信息中
        Map<String, Object> task = bidDao.getTaskInfoByTaskId((Integer) map.get("itemId"));
        if(task != null){
            //是否已竞标
            Integer count = taskDetailService.getUserBidinfoByTaskId((Integer) map.get("itemId"),(Integer) map.get("userId"));
            if(count == 0){
                bidDao.addBidInfo(map);
                result.put("status", 0);
            }else{
                result.put("status", -2);
            }

        }else{
            result.put("status", -1);
        }
        return result;
    }
}
